Download Demo Sitemap API

Edgar Model Convention



Contents
  1. name
    1. Address
      1. Manual setup
      2. Enum
        1. Example
        2. Bitset
          1. Example
          2. File upload
            Recent Updates
            How to use
            2012/12/23
            Edgar Model Convention
            2012/09/28
            Support and Consulting
            2012/09/19
            Feature
            2012/09/19
            index
            2012/09/19


            Japanese

            Edgar Model has the following convention so when using edgar_scaffold, naming of columns should comply that.

            [-] 1. name

            'Name' column or method is required when the model is used at popup-selection.

            The model, which is generated by edgar_scaffold, is *NOT* required to have 'name' column or method. However, when it is referred by other model as 'belongs_to', it is required to have 'name' since Edgar popup-selection uses it. So, it is recommended to have 'name' column or method at design phase of the model.

            [-] 2. Address

            (NOTE: Address feature is still under construction. Document in this section is just current way.)

            In order to add address in a model, declare by edgar_address as follows:

            class Author < ActiveRecord::Base
                :
              edgar_address :adrs
                :
            end

            Edgar::FieldHelper.draw_adrs() helper displays address.

            Address partial template app/views/edgar/_address.html.erb can be customized also if you don't like that ;-(...

            [-] 2.1. Manual setup

            Currently, edgar_address requires following manual logic to initialize address column (see test/dummy/app/models/author.rb as an example):

            class Author < ActiveRecord::Base
              ...
              def initialize(attrs = {})
                super
                self.adrs = Edgar::Address.new if self.adrs == nil
              end
            end

            [-] 3. Enum

            'Enum' in Edgar is a module which integer constants are defined. draw_enum() draws selection for an integer AR column.

            Selection-option label is I18n supported by AR human_const_name API.

            [-] 3.1. Example

            Following Question module's Priority selection on @question.priority integer column:

            <% edgar_form_for do |f| %>
                :
              <%= draw_enum(f, :priority) %>
                :
            <% end %>

            shows:

            config.default/locales/*.yml activerecord.enums.question/priority entry shows how selection-option label is I18n-ed.

            [-] 4. Bitset

            When an integer column 'xyz' is defined and there is 'XyzBitset' module which contains 2^n^ constants (e.g. bitflag 0x01, 0x02, 0x04, ...), Edgar::FieldHelper.draw_bitset() helper draws checkboxes for each bitflag.

            Each constant can be I18n.

            [-] 4.1. Example

            ModelPermission model is the actual example:

            class Edgar::ModelPermission < ActiveRecord::Base
                :
              module FlagsBitset
                CREATE  = 0x01
                READ    = 0x02
                UPDATE  = 0x04
                DELETE  = 0x08
              end
                :
            end

            Following example:

            <%= draw_flags(f, :flags) %>
                :

            shows:

            Where, f is FormBuilder variable.

            [-] 5. File upload

            There is no file upload support at Edgar level, but Paperclip + Remotipart work great! Please see Book model test/dummy/app/models/book.rb and Book view test/dummy/app/views/books/ how to use them.


            Get Edgar at SourceForge.net. Fast, secure and Free Open Source software downloads | Generated by juli 1.17.00